<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>主页</title>

    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/jqpaginator.min.js"></script>
</head>
<body>
    <h3>你好！${user.name}</h3>
    <table class="table table-striped">
        <thead>
        <tr>
            <th>id</th>
            <th>账号</th>
            <th>密码</th>
            <th>手机</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <#list users.list as user>

        <tr>
            <td>${user.id}</td>
            <td>${user.name}</td>
            <td>${user.pwd}</td>
            <td>${user.phone}</td>
            <td><a class="btn" href="/success/omnipotent?id=${user.id}" type="button"">修改</a>&nbsp;&nbsp;&nbsp;
                <button class="btn" btn="btn" type="button" did="${user.id}">删除</button></td>
        </tr>
        </#list>

        </tbody>
    </table>

    <div id="page" class="pagination"></div>
    <form id="pageForm" action="/success/index" method="post">
        <input id="pageNum" type="hidden" value="1" name="pageNum">
    </form>

<script>
    $('#page').jqPaginator({
        // 总页数
        totalPages:${users.pages},
        // 显示的页签个数
        visiblePages:5,
        // 总条数
        totalCounts:${users.total},
        // 当前页数
        currentPage:${users.pageNum},
        onPageChange: function (num, type) {
            if(num != ${users.pageNum}) {
                $("#pageNum").val(num);
                $("#pageForm").submit();
            }
        }
    });
    $(document).ready(function(){
      $("[btn='btn']").on("click",function () {
          var did = $(this).attr("did");
          $.ajax({
              type:'post',
              data:{"id":did},
              url:'/success/delete',
              success:function () {
                  window.location.href="/success/index";
              }
          })
      })
    })
</script>
</body>
</html>